package com.iuhao.web.test;

import com.google.common.collect.Lists;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by yanhao on 2017/11/20.
 */
public class JavaFilter {

    /***
     * 判断是否在LIST中
     */

    public static void main(String[] args) {
/*
        List<String> list = Lists.newArrayList();//新建一个List 用的google提供的Guava  package com.google.common.collect;
        list.add("1");
        list.add("2");
        list.add("3");

        list.stream().forEach(string ->{
            System.out.println(string);
        });*/


       // stream();//过滤
        Person person = new Person();
        person.setName("yanhao");
        person.setAge(11);
        Person person2 = new Person();
        person2.setName("yanhao2");
        person2.setAge(112);
        Person person3 = new Person();
        person3.setName("yanhao3");
        person3.setAge(11);


        List<Person> peoples = new ArrayList<>();
        peoples.add(person);
        peoples.add(person2);
        peoples.add(person3);
        Person person1 = peoples.stream().filter(x -> 112 == x.getAge()).findAny().orElse(null);

        System.out.println(peoples.size()+"-- :"+person1.getAge()+" --"+person1.getName());

    }





    private static void stream() {
        Long a=1l;

        List<Long> list1 = Lists.newArrayList();
        List<Long> list2 = Lists.newArrayList();
        list1.add(1l);
        list1.add(2l);
        list1.add(1l);
        list1.add(3l);

        list2 = list1.stream().filter(s -> s==a ).collect(Collectors.toList());

        System.out.println(list2.toString()+"--"+list2.size());
    }

    @Setter
    @Getter
    static   class  Person{
        private String name="闫";
        private int age;

    }
}
